package com.teemor.spring.boot.start.config;

import com.teemor.spring.boot.start.Formatter;
import com.teemor.spring.boot.start.impl.DefaultFormatter;
import com.teemor.spring.boot.start.impl.JsonFormatter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description:
 * @author zhoulk
 * @date: 2020/1/13
 */
@Configuration
public class FormatterAutoConfiguration {

    @Bean
    @ConditionalOnMissingClass(value = "com.fasterxml.jackson.databind.ObjectMapper") //当该类不存在时创建bean
    public Formatter defaultFormatter() {
        return new DefaultFormatter();
    }

    @Bean
    @ConditionalOnClass(value = com.fasterxml.jackson.databind.ObjectMapper.class) //当该类存在时创建bean
    public Formatter jsonFormatter() {
        return new JsonFormatter();
    }
}
